<?php
/**
 * Created by PhpStorm.
 * User: 宅十三
 * Date: 2021/11/22
 * Time: 11:41
 */
namespace app\demo\model;


use think\Model;

class Goods extends Model{
    //获取器
    public function getIsShowZhAttr($v,$d)   {return $d['is_show']?'是':'否';}
    public function getIsHotZhAttr($v,$d)    {return $d['is_hot']?'是':'否';}
    public function getIsDownZhAttr($v,$d)   {return $d['is_down']?'是':'否';}
    public function getAddtimeZhAttr($v,$d)  {return date('Y-m-d H:i:s',$d['addtime']);}
    //搜索器
    public function searchKeywordsAttr($q,$v,$d)
    {
$q->where('g.name','like',"%{$v}%");
    }

public function searchCidAttr($q,$v)
{
    $q->where('g.cid','=',$v);
}
    public function searchIsShowAttr($q,$v)
    {
        $q->where('g.is_show','=',$v);
    }
    public function searchIsHotAttr($q,$v)
    {
        $q->where('g.is_hot','=',$v);
    }
    public function searchIsDownAttr($q,$v)
    {
        $q->where('g.is_down','=',$v);
    }
    public function searchKTimeAttr($q,$v)
    {
        $q->where('g.addtime','> time',$v);
    }
    public function searchJTimeAttr($q,$v)
    {
        $q->where('g.addtime','< time',$v);
    }
    public function searchGPriceAttr($q,$v)
    {
        $q->where('g.price','<',$v);
    }
    public function searchDPriceAttr($q,$v)
    {
        $q->where('g.price','> time',$v);
    }




    public static function getGoodList($where = [])
    {
  $list = Goods::name('goods')
      ->alias('g')
      ->join('ecm_category c','g.cid = c.id','left')
      ->field('g.*,c.name cname')
      ->withSearch(array_keys($where),$where)
      ->paginate([
      'list_rows' =>5,
      'query'  => $where,
  ]);
  return $list;
    }
}